package com.atguigu.datasource;


import com.atguigu.bean.WaterSensor;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class Demo02 {
    public static void main(String[] args) {
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port",10000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);
        env.setParallelism(2);

        DataStreamSource<WaterSensor> datasource = env.addSource(new RandomWatersensor());

        datasource.flatMap(new FlatMapFunction<WaterSensor, WaterSensor>() {
            @Override
            public void flatMap(WaterSensor value, Collector<WaterSensor> out) throws Exception {
                if (value.getVc()>50){
                    out.collect(value);
                }
            }
        }).print();


        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
